// src/router/index.tsx

import { useRoutes } from 'react-router-dom';
import type { RouteObject } from 'react-router-dom';
import { Navigate } from 'react-router-dom';

import LoginPage from '@/views/LoginPage';
import CreateAccountPage from '@/views/CreateAccountPage';
import ScholarDashboard from '@/views/ScholarDashboard';
import SponsorDashboard from '@/views/SponsorDashboard';
import RequireAuth from '@/router/RequireAuth';
import RequireAdmin from '@/router/RequireAdmin';

const constantRoutes: RouteObject[] = [
  {
    path: '/',
    id: 'root',
    element: <Navigate to="/login" replace />,
  },
  {
    path: '/login',
    id: 'loginPage',
    element: <LoginPage />,
  },
  {
    path: '/create-account',
    id: 'createAccountPage',
    element: (
      <RequireAdmin>
        <CreateAccountPage />
      </RequireAdmin>
    ),
  },
  {
    path: '/scholars',
    id: 'scholarsdashboard',
    element: (
      <RequireAuth>
        <ScholarDashboard />
      </RequireAuth>
    ),
  },
  {
    path: '/sponsors',
    id: 'sponsorsdashboard',
    element: (
      <RequireAuth>
        <SponsorDashboard />
      </RequireAuth>
    ),
  },
  {
    path: '*',
    element: <Navigate to="/login" replace />,
  },
];

const Router = () => {
  const routes = useRoutes(constantRoutes);
  return routes;
};

export default Router;